package com.yangguang.huahui.ui.activitys;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.yangguang.huahui.R;
import com.yangguang.huahui.baseadapter.BaseQuickAdapter;
import com.yangguang.huahui.baseadapter.BaseViewHolder;
import com.yangguang.huahui.entity.Attention;
import com.yangguang.huahui.mvp.presenter.ChangePinPresenter;
import com.yangguang.huahui.mvp.view.ChangePinView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ChangePinActivity extends BaseMvpActivity<ChangePinView, ChangePinPresenter> implements ChangePinView {
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.btn_add)
    Button btn_add;
    @BindView(R.id.iv_search)
    ImageView iv_search;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.tv_description)
    TextView tv_description;
    AttentionAdapter mAdapter;
    private List<Attention.ListBean> listTab = new ArrayList<>();

    @OnClick({R.id.iv_back, R.id.btn_add, R.id.btn_finish})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_add:
                break;
            case R.id.btn_finish:
                break;
        }
    }
    @Override
    protected int initLayoutId() {
        return R.layout.activity_change_pin;
    }

    @Override
    protected void initView() {
        tv_title.setText(getString(R.string.attention_class));
        btn_add.setVisibility(View.VISIBLE);
        iv_search.setVisibility(View.GONE);
        mRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
        mAdapter = new AttentionAdapter(R.layout.gride_tab_list_item, null);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onSuccess(Attention attention) {
        mAdapter.addData(attention.getList());
        tv_description.setText(attention.getList().size() +"");
    }

    @Override
    public void onError() {

    }

    @Override
    protected ChangePinPresenter initPresenter() {
        return new ChangePinPresenter();
    }

    @Override
    protected void fetchData() {
        mPresenter.getAttention();
    }

    private class AttentionAdapter extends BaseQuickAdapter<Attention.ListBean>{

        public AttentionAdapter(int layoutResId, List<Attention.ListBean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, Attention.ListBean item) {
            helper.setText(R.id.tv_tab, item.getClassname());
        }
    }
}
